package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.UploadService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 钟涛
 * @version 1.0
 * @description: TODO
 * @date 2021/12/7 22:23
 */
@RestController
@RequestMapping("/admin/product")
public class UploadController {
    @Autowired
    private UploadService uploadService;
    @PostMapping("/fileUpload")
    public Result upload(@RequestPart("file") MultipartFile file){
        //上传成功需要返回文件访问路径
        String path = uploadService.uploadToMinio(file);
        if(path==null){
            return Result.fail();
        }
        return Result.ok(path);
    }
}
